// pages/artificer/order_detail/order_detail.js
var api = require('../../../api/api');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img:[1,2,3,4,5,6,7],
    page_begin:'',
    order_id:'',
    info:{},
    statusArr:[
      '待上门','服务中','已完成','待评价','已取消'
    ],
    host:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      host:api.host
    })
    if(options.page_begin){
      this.setData({
        page_begin:options.page_begin
      })
    }
    if(options.order_id){
      this.setData({
        order_id:options.order_id
      })
    }
    this.getAppointDetail()
  },

  callPhone(){
    let phone  = '';
    console.log(this.data.page_begin)
    if(this.data.page_begin == "carOrder"){
      if(this.data.info.worker){
        phone = this.data.info.worker.phone
      }else{
        phone = this.data.info.shop.phone
      }
    }else if(this.data.page_begin == "artificer"){
       phone  = this.data.info.user.mobile
    }
    console.log(phone)
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  openMap(){
    wx.openLocation({
      latitude:parseFloat(this.data.info.latitude),
      longitude:parseFloat(this.data.info.longitude),
      address:this.data.info.address,
      fail:function(err){
        console.log(err)
      }
    })
  },
  getAppointDetail(){
    api.get('/appoint/detail/'+this.data.order_id).then(res=>{
      this.setData({
        info:res.detail
      })
    })
  },
  toAppraise(){
    wx.navigateTo({
      url: '/pages/car_order/appraise/appraise?type=0&detail_id='+this.data.info.id,
    })
  },
    //预览图片
    previewImg(e) {
      let index = e.currentTarget.dataset.index;
      let key = e.currentTarget.dataset.key;
      let imgArr = this.data.info[key].images;
      wx.previewImage({
        current: imgArr[index],
        urls: imgArr
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})